package com.kt.controller;

import com.kt.domain.User;
import com.kt.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/resetPassword.do")
public class ResetPasswordServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String newPassword = req.getParameter("pw");
        UserServiceImp userServiceImp = new UserServiceImp();
        User user = userServiceImp.findByUsername(username);
        if (user != null) {
            user.setPassword(newPassword);
            userServiceImp.changeUserInfo(user);
        }
    }
}
